package com.gzdh.tang.modu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzdh.tang.modu.entity.Fk;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

public interface FkMapper extends BaseMapper<Fk> {
    //select * from (select ROW_NUMBER() OVER(Order by CARDNO ) AS RowId ,Fk.*
//from  Fk,mac_mainp_sbruan_kl where Fk.kl=mac_mainp_sbruan_kl.kl and mac_mainp_sbruan_kl.device_id=4
//  and (cardsn is not null or cardsn<>'') ) t
    @Select(" select * from (select ROW_NUMBER() OVER(Order by CARDNO ) AS RowId ,Fk.*  " +
            "from  Fk,mac_mainp_sbruan_kl where Fk.kl=mac_mainp_sbruan_kl.kl and mac_mainp_sbruan_kl.device_id= #{id}" +
            "  and (cardsn is not null or cardsn<>'')) t " +
            " where RowId between " +
            "        #{pageNum} and #{pageSize}")
    List<Fk> getFkByPageByDeviceId(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("id") Long id);

    @Select("select * from (select ROW_NUMBER() OVER(Order by cardNo) as RowId,cardno,kh,bqh,ksh,a.id,name,cardsn," +
            "cardsn_int as cardsnInt,fkrq,a.kl,kye,btye,validdate,sfbm,openid,isGuaShi,photo2," +
            "AliUserId,AliUserAgreement,AliAgreementNo,AliEmployeeId,btcs,zbtcs " +
            "from Fk a,mac_mainp_sbruan_kl b " +
            "where a.kl = b.kl and b.device_id = #{id} and (cardsn is not null and cardsn<>'')) t " +
            "where RowId between #{pageNum} and #{pageSize}")
    List<Fk> getFkByPage(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("id") Long id);

    @Select("exec SP_JIESUAN_ONECARD_ALLDATE #{cardno}")
    void spjiesuan(@Param("cardno") String cardno);


    @Select("select cardno from fk where cardsn=#{cardsn}")
    String getCardnoByCardsn(@Param("cardsn") String cardsn);

    @Select(" select count(*) from (select ROW_NUMBER() OVER(Order by CARDNO ) AS RowId ,Fk.*  " +
            "from  Fk,mac_mainp_sbruan_kl where Fk.kl=mac_mainp_sbruan_kl.kl and mac_mainp_sbruan_kl.device_id= #{id}" +
            "  and (cardsn is not null and cardsn<>'')) t ")
    public int getCount(@Param("id") Long id);

    @Select("select cardno from fk where cardsn=#{cardsn}")
    String getCardNo(@Param("cardsn") String cardsn);

    @Select("select cardNo,isUsed from qrCode where content = #{content}")
    Map<String,Object> getCardNoByQrCode(@Param("content") String content);

    @Update("update QrCode set IsUsed=1 where content=#{content}")
    void updateQrCode(@Param("content") String content);

    @Select("select sfbm from tsdc_set where posnum=#{posnum} and begdate<=#{date} and enddate>=#{date}")
    public List<String> getTsdc(@Param("posnum") String posnum, @Param("date") String date);

}
